package com.app.twth.ui.preprocess;


import com.app.twth.app.Constant;
import com.app.twth.base.BaseModel;
import com.app.twth.bean.BaseResponseEntity;
import com.app.twth.net.JsonCallBack;
import com.app.twth.utils.GsonUtil;
import com.app.twth.utils.Utils;
import com.lzy.okgo.OkGo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class PreprocessDataModel extends BaseModel {
    public <T> void returnPreprocessCheckTackingCode(String trackingCode, JsonCallBack jsonCallBack) {
        Map<String, String> map = new HashMap<>();
        map.put("trackingCode", trackingCode);

        OkGo.<BaseResponseEntity<T>>get(Constant.returnPreprocessCheckTackingCode)
                .tag(this)
                .params(map)
                .execute(jsonCallBack);
    }

    public <T> void getInfoByBarcode(String sku, JsonCallBack jsonCallBack) {
        Map<String, String> map = new HashMap<>();
        map.put("sku", sku);
        OkGo.<BaseResponseEntity<T>>get(Constant.getInfoByBarcode)
                .tag(this)
                .params(map)
                .execute(jsonCallBack);
    }

    public <T> void upload(String filePath, String path, JsonCallBack jsonCallBack) {
        File file = null;
        try {
            if (Utils.isEmpty(path)) {
                return;
            }
            file = new File(path);
            if (file == null) {
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> map = new HashMap<>();
        map.put("filePath", filePath);
        OkGo.<BaseResponseEntity<T>>post(Constant.upload)
                .tag(this)
                .params(map)
                .params("file", file)
                .execute(jsonCallBack);
    }

    public <T> void returnPreprocessSubmit(PreprocessQr preprocessQr, JsonCallBack jsonCallBack) {
        OkGo.<BaseResponseEntity<T>>post(Constant.returnPreprocessSubmit)
                .tag(this)
                .upJson(GsonUtil.toJson(preprocessQr))
                .execute(jsonCallBack);
    }

}